cmake_minimum_required(VERSION 3.12)

#Component name, default the same as directory name
get_filename_component(component_dir ${CMAKE_PARENT_LIST_FILE} DIRECTORY)
get_filename_component(component_name ${component_dir} NAME)
project(${component_name})

unset(COMPONENT_NAME)
unset(COMPONENT_UPPER_NAME)
# set(COMPONENT_NAME template)
set(COMPONENT_NAME ${PROJECT_NAME})
string(TOUPPER ${COMPONENT_NAME} COMPONENT_UPPER_NAME)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/commit.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/option.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/include.cmake)

if(NOT DEFINED BUILD_STATIC_LIBS)
    set(BUILD_STATIC_LIBS ON)
endif()
if(NOT DEFINED BUILD_SHARED_LIBS)
    set(BUILD_SHARED_LIBS ON)
endif()
if(NOT DEFINED BUILD_EXAMPLES)
    set(BUILD_EXAMPLES ON)
endif()
if(NOT DEFINED BUILD_TESTS)
    set(BUILD_TESTS ON)
endif()
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug | Release." FORCE)
endif()

add_subdirectory(source)

if(${BUILD_EXAMPLES} STREQUAL "ON")
    add_subdirectory(example)
endif()

if(${BUILD_TESTS} STREQUAL "ON")
    add_subdirectory(unittest)
endif()

######################################################################

# uninstall targget
if(NOT TARGET uninstall)
    configure_file(
        "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    IMMEDIATE @ONLY)

    add_custom_target(uninstall
        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
